package org.example.controller.defaultDir;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.example.model.common.PageResponseDto;
import org.example.model.common.ResponseResult;
import org.example.model.diary.dtos.DiaryContentByMonthDto;
import org.example.model.diary.dtos.DiaryCountGroupByDayDto;
import org.example.model.diary.dtos.DiaryInfoDto;
import org.example.model.diary.vos.AddDiaryInfoVo;
import org.example.model.diary.vos.SearchDiaryInfoVo;
import org.example.service.diary.DiaryInfoService;
import org.example.controller.common.permission.PermissionControl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 日报信息表现层
 */
@CrossOrigin
@RestController
@RequestMapping("/diary-info")
@Api(value = "日报信息接口", tags = {"日报信息接口"})
@PermissionControl(Name = "日报管理", Order = 2)
public class DiaryInfoController {

    @Autowired
    private DiaryInfoService diaryInfoService;

    /**
     * 添加一条默认的日报信息
     * @param belongUserId 日报所属人id
     */
    @PostMapping("{belongUserId}")
    @ApiOperation("添加一条默认的日报信息")
    @PermissionControl(Parent = "日报管理", Name = "添加", Order = 1)
    public ResponseResult<Boolean> AddDiaryInfo(@PathVariable Integer belongUserId) {
        return diaryInfoService.InsertDiaryInfo(belongUserId);
    }

    /**
     * 根据条件（创建时间）分页查询日报信息
     * @param searchDiaryInfoVo 查询条件
     */
    @GetMapping("/diary-list")
    @ApiOperation("根据条件（创建时间）分页查询日报信息")
    @PermissionControl(Parent = "日报管理", Name = "查询", Order = 4)
    public ResponseResult<PageResponseDto<List<DiaryInfoDto>>> GetDiaryInfoList(SearchDiaryInfoVo searchDiaryInfoVo) {
        return diaryInfoService.SelectDiaryInfoListByConditions(searchDiaryInfoVo);
    }

    /**
     * 根据id修改一则日报信息记录
     * @param addDiaryInfoVo 要修改日志信息
     */
    @PutMapping
    @ApiOperation("根据id修改一则日报信息记录")
    @PermissionControl(Parent = "日报管理", Name = "修改", Order = 3)
    public ResponseResult<Boolean> UpdateDiaryInfoById(@RequestBody AddDiaryInfoVo addDiaryInfoVo) {
        return diaryInfoService.UpdateDiaryInfoById(addDiaryInfoVo);
    }

    /**
     * 根据id删除一则日报信息记录
     * @param id 日报信息id
     */
    @DeleteMapping("{id}")
    @ApiOperation("根据id删除一则日报信息记录")
    @PermissionControl(Parent = "日报管理", Name = "删除", Order = 2)
    public ResponseResult<Boolean> DeleteDiaryInfoById(@PathVariable int id) {
        return diaryInfoService.DeleteDiaryInfoById(id);
    }

    /**
     * 获取本月的日报详情列表
     */
    @GetMapping("/diary-content-month")
    @ApiOperation("获取本月的日报详情列表")
    public ResponseResult<List<DiaryContentByMonthDto>> GetDiaryListByMonth(SearchDiaryInfoVo searchDiaryInfoVo) {
        return diaryInfoService.GetDiaryListByMonth(searchDiaryInfoVo);
    }

    /**
     * 获取每天的日报数
     */
    @GetMapping("/diary-count-day")
    @ApiOperation("获取每天的日报数")
    ResponseResult<List<DiaryCountGroupByDayDto>> GetCurrentDayDiaryCount(){
        return diaryInfoService.GetCurrentDayDiaryCount();
    }
}
